<template>
  <div>
    <div class="address_select">
      <v-distpicker province="河南省" city="濮阳市" area="南乐县"></v-distpicker>
      <el-button style="margin-left: 20px">查询</el-button>
    </div>
    <div style="display:flex">
      <div id="policy_chart"></div>
      <div id="work_chart"></div>
    </div>
    <div>
      <div id="business_chart"></div>
    </div>
  </div>
</template>

<script>
import VDistpicker from 'v-distpicker'
import echarts from 'echarts/lib/echarts'
import 'echarts/lib/chart/bar'
import 'echarts/lib/component/title'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/pie'
import 'echarts/lib/component/legend'
export default {
  components: {
    VDistpicker: VDistpicker
  },
  methods: {
    initPolicyChart () {
      const myChart = echarts.init(document.getElementById('policy_chart'))
      const option = {
        title: {
          text: '南乐县扶贫政策'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: [
          {
            type: 'category',
            data: ['2015', '2016', '2017', '2018', '2019', '2020'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [{ type: 'value' }],
        series: [
          {
            name: '扶贫政策',
            type: 'bar',
            barWidth: '40%',
            data: [50, 90, 120, 130, 100, 20]
          }
        ],
        grid: {
          top: 50,
          x: 45,
          y: 45,
          x2: 30,
          y2: 30
        }
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initWorkChart () {
      const myChart = echarts.init(document.getElementById('work_chart'))
      const option = {
        title: {
          text: '南乐县促就业政策'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: [
          {
            type: 'category',
            data: ['2015', '2016', '2017', '2018', '2019', '2020'],
            axisTick: {
              alignWithLabel: true
            }
          }
        ],
        yAxis: [{ type: 'value' }],
        series: [
          {
            name: '促就业政策',
            type: 'line',
            smooth: true,
            data: [60, 79, 90, 109, 123, 30]
          }
        ],
        grid: {
          top: 50,
          x: 45,
          y: 45,
          x2: 30,
          y2: 30
        }
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    },
    initBusinessChart () {
      const myChart = echarts.init(document.getElementById('business_chart'))
      const option = {
        title: {
          text: '政策涉及领域',
          x: 'right'
        },
        series: [
          {
            name: '领域',
            type: 'pie',
            data: [
              { value: 12, name: '建筑业' },
              { value: 20, name: '旅游业' },
              { value: 40, name: '技能培训' },
              { value: 23, name: '服务业' },
              { value: 60, name: '农业' },
              { value: 18, name: '服装餐饮' }
            ]
          }
        ]
      }
      myChart.setOption(option)
      // 建议加上以下这一行代码，不加的效果图如下（当浏览器窗口缩小的时候）。超过了div的界限（红色边框）
      window.addEventListener('resize', function () { myChart.resize() })
    }
  },
  mounted () {
    this.initPolicyChart()
    this.initWorkChart()
    this.initBusinessChart()
  }
}
</script>

<style lang="less" scoped>
.address_select{
  width: 700px;
  line-height: 40px;
  display: flex;
}
#policy_chart{
  width: 50%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#work_chart{
  width: 50%;
  height: 270px;
  margin: 10px 10px;
  background-color: white;
}
#business_chart{
  width: 50%;
  height: 270px;
  margin: 10px 25%;
  background-color: white;
}
</style>
